from certificate_manager.models import *
from certificate_manager.serializers import DepartmentSerializer, UserSerializer, CertSerializer
from django.test import tag
from rest_framework import status
from rest_framework.renderers import JSONRenderer
from rest_framework.test import APITestCase, force_authenticate
import datetime

class UnloginedAccountTests(APITestCase):
	'''
	在这里我们要模拟用户的全部操作，包括注册、登陆、登出、更改用户相关信息
	'''
	def setUp(self):
		# 我们只需要把部门解决了，其他的就没问题
		Department.objects.create(name='test_department').save()
		self.cur_user = User.objects.create_user(uid='1111', name='wyw', department=Department.objects.get(name='test_department'), password='123')
	
	def test_regist(self):
		url = '/users/'
		data = { 'uid': '1813004316', 'name': 'Yves', 'password': '123', 'department': 1 }
		response = self.client.post(url, data, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)
		self.assertEqual(User.objects.count(), 2)
	pass

	def test_login(self):
		# 登陆应该用哪个接口呢? 现在注册占了POST了
		# 虽然内部提供了登陆方法 但这并不是用户可以访问到的
		url = '/login/'
		data = { 'uid': '1111', 'password': '123'  }
		response = self.client.post(url, data, format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)
		pass

	def test_login_faild(self):
		url = '/login/'
		data = { 'uid': 'x1111', 'password': '123'  }
		response = self.client.post(url, data, format='json')
		self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
		pass
